package com.teamcenter.rac.massupdate.ui;

import org.apache.log4j.Logger;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.views.properties.IPropertySource;

import com.teamcenter.rac.aifrcp.AbstractBindingDialog;
import com.teamcenter.rac.aifrcp.AifrcpPlugin;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.massupdate.Activator;
import com.teamcenter.rac.viewer.sorter.PropertyColumnViewerSorter;

public abstract class AbstractMassUpdateDialog extends AbstractBindingDialog {
	private TCSession m_tcSession;

	protected AbstractMassUpdateDialog(Shell paramShell) {
		super(paramShell);
	}

	protected Point getInitialSize() {
		if (dialogSettingExists()) {
			return super.getInitialSize();
		}
		return new Point(800, 700);
	}

	protected TCSession getTCSession() {
		try {
			if (this.m_tcSession == null) {
				this.m_tcSession = ((TCSession) Activator.getDefault().getSessionService()
						.getSession(TCSession.class.getName()));
			}
		} catch (Exception localException) {
			Logger.getLogger(AbstractMassUpdateDialog.class).error(localException.getLocalizedMessage(),
					localException);
		}
		return this.m_tcSession;
	}

	protected boolean dialogSettingExists() {
		if (AifrcpPlugin.getDefault() == null) {
			return false;
		}
		IDialogSettings localIDialogSettings1 = AifrcpPlugin.getDefault().getDialogSettings();
		String str = getClass().getName();
		IDialogSettings localIDialogSettings2 = localIDialogSettings1.getSection(str);
		return localIDialogSettings2 != null;
	}

	protected static class IC_PropertyColumnViewerSorter extends PropertyColumnViewerSorter {
		protected Object getValue(Object paramObject, String paramString, int paramInt, Viewer paramViewer) {
			if ((paramObject instanceof IPropertySource)) {
				return ((IPropertySource) paramObject).getPropertyValue(paramString);
			}
			return super.getValue(paramObject, paramString, paramInt, paramViewer);
		}
	}
}
